//
//  HAccountCell.m
//  BXlive
//
//  Created by bxlive on 2017/5/5.
//  Copyright © 2017年 cat. All rights reserved.
//

#import "HAccountCell.h"
#import <Masonry/Masonry.h>
#import <SLDeveloperTools/SLDeveloperTools.h>
#import "GradientButton.h"
@interface HAccountCell()

@property (nonatomic,strong) UIImageView *iconImageView;         //图标
@property (nonatomic,strong) UILabel *titleLabel;                //标题
@property (strong, nonatomic) UIButton *bindBtn;
@property (nonatomic,strong) UIImageView *nextImageView;         //跳转箭头

@end

@implementation HAccountCell
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    HAccountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HAccountCell"];
    if (cell == nil) {
        cell = [[HAccountCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HAccountCell"];
    }
    return cell;
}

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

/**
 *  初始化控件
 */
- (void) setupUI {
    self.iconImageView = [UIImageView new];
    [self.contentView addSubview:self.iconImageView];
    
    WS(weakSelf);
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(__ScaleWidth(28));
        make.left.mas_equalTo(__ScaleWidth(12));
        make.centerY.mas_equalTo(0);
    }];
    
    self.titleLabel = [UILabel initWithFrame:CGRectZero size:13 color:sl_textColors alignment:NSTextAlignmentLeft lines:1];
    self.titleLabel.font = SLBFont(__ScaleWidth(15));
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.iconImageView.mas_right).offset(__ScaleWidth(15));
        make.height.mas_equalTo(__ScaleWidth(21));
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(__ScaleWidth(100));
    }];
    
    
//    self.fengeView = [[UIView alloc]initWithFrame:CGRectZero];
//    self.fengeView.backgroundColor = LineNormalColor;
//    [self.contentView addSubview:self.fengeView];
    
    self.nextImageView = [UIImageView new];
    self.nextImageView.image = [UIImage imageNamed:@"箭头下一步"];
    [self.contentView addSubview:self.nextImageView];
   
    [self.nextImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(__ScaleWidth(8));
        make.height.mas_equalTo(__ScaleWidth(12));
        make.right.mas_equalTo(__ScaleWidth(-12));
    }];
    
    self.bindBtn = [[GradientButton alloc] initWithFrame:CGRectZero];
    self.bindBtn.titleLabel.font = SLPFFont(14);
    self.bindBtn.layer.masksToBounds = YES;
    self.bindBtn.layer.cornerRadius = __ScaleWidth(14);
    [self.bindBtn setTitleColor:sl_whiteTextColors forState:UIControlStateNormal];
    [self.bindBtn setTitleColor:sl_textSubColors forState:UIControlStateSelected];
    [self.bindBtn setTitle:NSLocalizedString(@"绑定", nil) forState:UIControlStateNormal];
    [self.bindBtn setTitle:NSLocalizedString(@"已绑定", nil) forState:UIControlStateSelected];
    [self.bindBtn addTarget:self action:@selector(bandBtnClick) forControlEvents:UIControlEventTouchUpInside];

    [self.contentView addSubview:self.bindBtn];
    [self.bindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(__ScaleWidth(-12));
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(__ScaleWidth(58));
        make.height.mas_equalTo(__ScaleWidth(28));
    }];
    
//    self.bindBtn.sd_layout.rightSpaceToView(self.contentView,15).centerYEqualToView(self.contentView);
//    [self.bindBtn setupAutoSizeWithHorizontalPadding:15.f buttonHeight:30];
    
//    self.iconImageView.sd_layout.leftSpaceToView(self.contentView,15).centerYEqualToView(self.contentView).widthIs(26).heightIs(26);
//    self.titleLabel.sd_layout.leftSpaceToView(self.iconImageView,13).topSpaceToView(self.contentView,0).bottomSpaceToView(self.contentView,0).widthIs(100);
//    self.nextImageView.sd_layout.rightSpaceToView(self.contentView,15).centerYEqualToView(self.contentView).widthIs(7).heightIs(12);
}

- (void)setTitle:(NSString *)title icon:(NSString *)icon isBind:(BOOL)isBind {
    _titleLabel.text = title;
    _iconImageView.image = CImage(icon);
    if (isBind) {
        _bindBtn.backgroundColor = sl_subBGColors;
    } else {
        _bindBtn.backgroundColor = sl_normalColors;
    }
    _bindBtn.selected = isBind;
    _bindBtn.userInteractionEnabled = !isBind;
}

- (void)bandBtnClick {
    if (_bindThird) {
        _bindThird(_type);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
